package com.cskaoyan.wx.controller;

import com.cskaoyan.vo.BaseRespVo;

import com.cskaoyan.wx.bo.AddressSaveBO;
import com.cskaoyan.wx.service.WxAddressService;

import com.cskaoyan.wx.vo.AddressRegionVO;
import com.cskaoyan.wx.vo.ReceiveAddressDetailVO;
import com.cskaoyan.wx.vo.ReceiveAddressVO2;
import org.apache.catalina.mapper.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx")
public class WxAddressController {

    @Autowired
    WxAddressService wxAddressService;

    @GetMapping("address/list")
    public BaseRespVo receiveAddressList(){
        List<ReceiveAddressVO2> receiveAddressVOS = wxAddressService.getAddressList();
        return BaseRespVo.ok(receiveAddressVOS);
    }

    @GetMapping("address/detail")
    public BaseRespVo addressDetail(Integer id) {
        ReceiveAddressDetailVO receiveAddressDetailVO = wxAddressService.getAddressDetail(id);
        return BaseRespVo.ok(receiveAddressDetailVO);
    }

    @PostMapping("address/save")
    public BaseRespVo addressSave(@RequestBody AddressSaveBO addressSaveBO) {
        wxAddressService.getAddressSave(addressSaveBO);
        return BaseRespVo.ok(addressSaveBO.getId());
    }
    //
    // @GetMapping("region/list")
    // //有一个pid
    // public BaseRespVo regionList(Integer pid) {
    //     List<AddressRegionVO> addressRegionVO = wxAddressService.getRegionList(pid);
    //     return BaseRespVo.ok(addressRegionVO);
    // }

    @PostMapping("address/delete")
    public BaseRespVo deleteAddress(@RequestBody  AddressRegionVO addressRegionVO ) {
        wxAddressService.deleteAddress(addressRegionVO.getId());
        return BaseRespVo.ok();
    }

}
